package com.ems.service.impl;

import com.ems.entity.BatteryVoltageEntity;
import com.ems.mapper.BatteryVoltageMapper;
import com.ems.service.IBatteryVoltageService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ems.util.SnowflakeIdWorker;
import com.ems.util.StateEnum;
import com.ems.util.StateException;
import com.ems.vo.BatteryVoltageVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 电池电压 服务实现类
 * </p>
 * @author WuZH
 * @since 2024-04-23
 */
@Service
public class BatteryVoltageServiceImpl extends ServiceImpl<BatteryVoltageMapper, BatteryVoltageEntity> implements IBatteryVoltageService {

    @Resource
    private BatteryVoltageMapper batteryVoltageMapper;

    @Override
    public BatteryVoltageVo saveSingle (BatteryVoltageVo batteryVoltageVo) {
        if ( batteryVoltageVo == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        BatteryVoltageEntity batteryVoltageEntity = new BatteryVoltageEntity ();
        BeanUtils.copyProperties ( batteryVoltageVo, batteryVoltageEntity );
        batteryVoltageEntity.setId ( SnowflakeIdWorker.getInstance ().nextStringId () );
        batteryVoltageEntity.setCreateTime ( new Date () );
        int insert = baseMapper.insert ( batteryVoltageEntity );
        if ( insert == 0 ) {
            throw new StateException ( StateEnum.INSERT_EXCE );
        }
        return batteryVoltageVo;
    }

    @Override
    public List<BatteryVoltageVo> queryList (BatteryVoltageVo batteryVoltageVo) {
        if ( batteryVoltageVo == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        List<BatteryVoltageVo> batteryVoltageVos = batteryVoltageMapper.queryList ( batteryVoltageVo );
        return batteryVoltageVos;
    }

    @Override
    public Integer queryCount (BatteryVoltageVo batteryVoltageVo) {
        if ( batteryVoltageVo == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        Integer count = batteryVoltageMapper.queryCount ( batteryVoltageVo );
        return count;
    }

}
